package testGuava.example.testSpring;

import org.junit.Test;
import testGuava.example.testSpring.bean.UserDao;
import testGuava.example.testSpring.bean.BaseDao;
import org.springframework.core.GenericTypeResolver;

/**
 * @ClassName : org.example.testSpring.GenericTypeResolvertest
 * @Description : 类描述
 * Created by cyd on 2021-09-15 17:08:55
 */
public class GenericTypeResolverTest {

    /**
     * 传统做法
     * 让父类的泛型，获得子类传入的Person泛型信息
     */
    @Test
    public void test() {
        new UserDao().getGenericSuperclass();
    }

    /**
     * 获得UserDao类声明的时候，传给BaseDao的泛型类型
     * 如果不用这个简易api，就需要在UserDao中用构造函数来传，并设置一个getGenericSuperclass方法，很麻烦
     */
    @Test
    public void test02() {
        // GenericTypeResolver.resolveTypeArgument()
        Class<?> aClass = GenericTypeResolver.resolveTypeArgument(UserDao.class, BaseDao.class);
        System.out.println(aClass.getName());
    }
}
